home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 June
/
EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso
/
earcd
/
comm1
/
qwesorcs.lha
/
qwe_sources
/
cdnet
/
CDNet.c
next >
Wrap
Text File
|
1995-12-16
|
7KB
|
487 lines
const char *_VERSION="\0$VER: CDNet 1.2 (27.08.95)";
#include <cnet/empty.h>
#include <dos/dos.h>
FILE *fp;
char key[3],
indexpfad[81]="pfiles:cdnet/",
treepfad[81]="pfiles:cdnet/",
ansipfad1[25]="pfiles:cdnet/cdnet.ansi1",
ansipfad2[25]="pfiles:cdnet/cdnet.ansi2",
readmepfad[81],
filepfad[81],
pfad[15],
line_a[150],
line_b[150],
tree[300][80];
UBYTE anz_tree,
pos=1,
merkpos,
zeilen,
merkzeilen;
BOOL files=FALSE,
more;
int zeiger,filenummer;
UBYTE x,y,i,j,k;
char *speicher,*p,*p2,*p3,*pp[2000];
ULONG laenge,bytes;
short merkanzahl;
byte moremode;
struct FileLock *lock;
struct FileInfoBlock *fib_ptr; /* Declare a FileInfoBlock */
/* pointer called fib_ptr. */
void blank(UBYTE t_pos)
{
sprintf(line_b,"%d;1H ",t_pos+4);
PutText(line_b);
}
void cursor(UBYTE t_pos)
{
sprintf(line_b,"%d;1H>D",t_pos+4);
PutText(line_b);
}
void copyindex(UBYTE letzte_zeile)
{
if(*p=='#' || *p==0)
{
more=FALSE;
return;
}
j=0;
while(*p!=10)
{
line_a[j++]=*p++;
}
line_a[j]=10;
line_a[j+1-letzte_zeile]=0;
p++;
}
void rauf(void)
{
if(pos>1)
{
blank(pos);
pos--;
cursor(pos);
}
else
{
if(files)
{
if(filenummer>zeilen+1)
{
more=TRUE;
filenummer--;
p=pp[filenummer-zeilen-1];
copyindex(1);
blank(pos);
sprintf(line_b,"HL%d;1H",pos+4);
PutText(line_b);
PutText(line_a);
cursor(pos);
}
}
else
{
if(zeiger>0)
{
blank(pos);
zeiger--;
sprintf(line_a,"HL%s",tree[zeiger]);
PutText(line_a);
cursor(pos);
}
}
}
}
void runter(void)
{
if(pos<zeilen)
{
p=pp[filenummer-zeilen+pos];
blank(pos);
pos++;
cursor(pos);
}
else
{
if(files)
{
if(more)
{
if(more)
{
copyindex(1);
if(more)
{
pp[filenummer++]=p;
blank(pos);
sprintf(line_b,"HM%d;1H",pos+4);
PutText(line_b);
PutText(line_a);
cursor(pos);
}
}
}
}
else
{
if(zeiger+pos-1<anz_tree)
{
blank(pos);
zeiger++;
sprintf(line_a,"HM%d;1H",pos+4);
PutText(line_a);
PutText(tree[zeiger+pos-1]);
cursor(pos);
}
}
}
}
void info(void)
{
strcpy(line_b,readmepfad);
AddPart(line_b,pfad,80);
p2=line_a;
p3=pp[filenummer-zeilen-2+pos];
p3++;
while(*p3!=32)
{
*p2++=*p3++;
}
strcpy((p2-3),"readme\0");
AddPart(line_b,line_a,80);
z->user1.MoreMode=1;
PutText("F1");
ReadFile(line_b,0);
PutText("C7Press RETURN to continueG0");
z->user1.MoreMode=0;
ReadFile(ansipfad2,0);
sprintf(line_a,"3H%d 1H%d H",z->NoSelected,bytes/1000);
PutText(line_a);
p=pp[filenummer-zeilen-1];
for(i=filenummer-zeilen-1;i<filenummer-2;i++)
{
copyindex(0);
PutText(line_a);
}
copyindex(1);
PutText(line_a);
cursor(pos);
}
void dirs(void)
{
i=0;
if(files)
{
ReadFile(ansipfad2,0);
sprintf(line_a,"3H%d 1H%d H",z->NoSelected,bytes/1000);
PutText(line_a);
more=TRUE;
while(i<zeilen-1 && more)
{
copyindex(0);
if(more)
{
pp[filenummer++]=p;
PutText(line_a);
i++;
}
}
if(more)
{
copyindex(1);
if(more)
{
pp[filenummer++]=p;
PutText(line_a);
}
}
merkzeilen=zeilen;
zeilen=filenummer-1;
}
else
{
ReadFile(ansipfad1,0);
sprintf(line_a,"3H%d 1H%d H",z->NoSelected,bytes/1000);
PutText(line_a);
while(i<zeilen-1)
{
sprintf(line_a,"%s\n",tree[i+zeiger]);
PutText(line_a);
i++;
}
sprintf(line_a,"%s",tree[i+zeiger]);
PutText(line_a);
}
cursor(pos);
}
void go_files(void)
{
j=1;
while(tree[zeiger+pos-1][j]!=' ') /* suchstring erstellen */
{
line_a[j]=tree[zeiger+pos-1][j];
j++;
}
line_a[j]=0;
line_a[0]='#';
strcpy(pfad,line_a+1);
if(p=strstr(speicher,line_a))
{
while(*p!=10) /* naechste zeile suchen */
{
p++;
}
p++;
merkpos=pos;
pos=1;
files=TRUE;
filenummer=0;
pp[filenummer++]=p;
dirs();
}
}
void select_files(void)
{
strcpy(line_b,filepfad);
AddPart(line_b,pfad,80);
p2=line_a;
p3=pp[filenummer-zeilen-2+pos];
p3++;
while(*p3!=32)
{
*p2++=*p3++;
}
*p2=0;
AddPart(line_b,line_a,80);
PutText("H F0");
SelectAndDownload(line_b,FALSE);
i=0;
bytes=0;
while(i<z->NoSelected)
{
bytes+=z->Select[i++].Size;
}
if(merkanzahl<z->NoSelected)
{
z->Select[z->NoSelected-1].CDROM=1;
}
merkanzahl=z->NoSelected;
sprintf(line_a,"3H%d 1H%d ",z->NoSelected,bytes/1000);
PutText(line_a);
PutText(line_a);
cursor(pos);
}
main(int argc,char **argv)
{
PreMain(argc,argv); /*** Let it here, dute! ***/
AddPart(indexpfad,argv[2],80);
AddPart(treepfad,argv[2],80);
AddPart(indexpfad,"index",80);
AddPart(treepfad,"tree",80);
strcpy(readmepfad,argv[3]);
AddPart(readmepfad,"aminet/",80);
strcpy(filepfad,argv[3]);
AddPart(filepfad,"aminet/",80);
zeilen=z->user1.TermLength-4;
if(z->user1.Colors==0 || z->user1.ANSI!=2)
{
PutText("n1Mindestvorraussetzung fuer CDNetn1--------------------------------n2Full Ansi + 8 Farbenn2");
}
else
{
SetDoing("CDNet");
moremode=z->user1.MoreMode;
/* index */
fib_ptr=(struct FileInfoBlock *) AllocMem( sizeof(struct FileInfoBlock),MEMF_PUBLIC|MEMF_CLEAR);
if(fib_ptr==NULL)
{
PutText("Not enough memory!\n");
goto hell;
}
lock=(struct FileLock *) Lock(indexpfad,SHARED_LOCK);
if(lock==NULL)
{
PutText("Could not lock pfiles:cdnet/.../index !\n");
/* Deallocate the memory we have allocated: */
FreeMem(fib_ptr,sizeof(struct FileInfoBlock));
goto hell;
}
if( Examine(lock,fib_ptr)==NULL)
{
PutText("Could not examine pfiles:cdnet/.../index !\n");
FreeMem(fib_ptr,sizeof(struct FileInfoBlock));
UnLock(lock);
goto hell;
}
laenge=fib_ptr->fib_Size;
speicher=AllocMem(laenge+1,MEMF_PUBLIC|MEMF_CLEAR);
UnLock(lock);
FreeMem(fib_ptr,sizeof(struct FileInfoBlock));
if (fp=fopen(indexpfad,"r"))
{
fread(speicher,laenge,1,fp);
fclose(fp);
}
else
{
PutText("Could not load pfiles:cdnet/.../index !\n");
goto hell;
}
*(speicher+laenge)=0;
if (fp=fopen(treepfad,"r"))
{
i=0;
while(fgets(tree[i],sizeof(tree[0]),fp))
{
tree[i][strlen(tree[i])-1]=0;
i++;
}
fclose(fp);
anz_tree=i-1;
}
else
{
PutText("Could not load pfiles:cdnet/.../tree !\n");
goto hell2;
}
i=0;
bytes=0;
while(i<z->NoSelected)
{
bytes+=z->Select[i++].Size;
}
merkanzahl=z->NoSelected;
z->user1.MoreMode=0;
dirs();
do
{
key[0]=CNetGetKey();
switch (key[0])
{
case '':
{
key[0]=CNetGetKey();
if (key[0]==91)
{
key[0]=CNetGetKey();
if (key[0]=='A')
{
rauf();
}
if (key[0]=='B')
{
runter();
}
}
break;
}
case ' ':
{
if(files)
{
select_files();
}
break;
}
case 13:
{
if(!files)
{
go_files();
}
break;
}
case 'I':
{
if(files)
{
info();
}
break;
}
case 'P':
{
if(files)
{
zeilen=merkzeilen;
pos=merkpos;
files=FALSE;
dirs();
}
break;
}
}
}
while (key[0]!=81 && z->TimeLeft!=0);
z->user1.MoreMode=moremode;
PutText("@0F1");
}
hell2:
FreeMem(speicher,laenge+1);
hell:
PostMain(); /*** Must be here ***/
}